package api_day16;

import java.io.IOException;

/**
 * day15开始做项目，day16考试，此为考试疑点题目测试用类 day17也是项目
 */
public class TestDemo {
    //线程通信，wait与sleep的区别之一测试： sleep 不释放对象锁，wait 放弃对象锁
    public static void main(String[] args) throws InterruptedException {
        final Object obj = new Object();
        Thread t1 = new Thread(){
            public void run(){
                synchronized (obj){
                    try{
                        System.out.println("Thread 1 sleep.");
                        Thread.sleep(10000);
                        System.out.println("Thread 1 wake up.");
                        obj.wait();
                        System.out.println("Thread 1 wake up.");
                    }catch (InterruptedException e){
                    }
                }
            }
        };
        t1.start();
        Thread.sleep(1000);
        Thread t2 = new Thread(){
            public void run(){
                synchronized (obj){
                    obj.notifyAll();
                    System.out.println("Thread 2 sent notify.");
                }
            }
        };
        t2.start();
    }
}